<template>
    <main-wrap >
        <div class="fmbox">
            <input type="text" v-model="state" placeholder="请输入客户来源"/>
            <span @click="reCreate">重新生成</span>
        </div>
        <div class="tips">注：这里填写来源创建的二维码，当客户扫描后，就会为客户标注该填写的来源！</div>
        <div class="qrBox">
            <img v-if="qrCode" :src="qrCode" alt="二维码"/>
        </div>
        <!-- <template v-slot:footer>
            <footer-nav/>
        </template> -->
    </main-wrap>
</template>
<script setup>
import { ref,onMounted,nextTick } from "vue";
import {useRouter} from 'vue-router'

import {getJoinQrCode} from '@/api/qy-wechat-api'
import {toast,loading,clearToast} from '@/utils/vant'
import { useUserStore } from '@/stores/modules/user'
import mainWrap from '@/components/mainWrap.vue'
import footerNav from '@/components/footerNav.vue'
import { showConfirmDialog } from 'vant';
import 'vant/es/dialog/style';

const router = useRouter()
const userStore = useUserStore()
const state = ref('')
const qrCode = ref('')

onMounted(async ()=>{
    createQr()
})

const createQr = async ()=>{
    // 生产二维码
    const res = await getJoinQrCode({userid:userStore.userInfo.userid,state:state.value})
    qrCode.value = res.data.qr_code
    state.value = ''
}

const reCreate = ()=>{
    let msg = '重新生成不带有来源标注的二维码'
    if(state.value){
        msg = `重新生成带有来源标注为 ‘${state.value}’ 的二维码！`
    }
    showConfirmDialog({
        title: '提示',
        message:msg,
    })
    .then(() => {
        createQr()
    })
    .catch(() => {
        // on cancel
    });
}


</script>

<style lang="scss">
.fmbox{
    display: flex;
    padding: 20px;
    input{
        flex: 1;
        border: 1px solid #eee;
        height: 80px;
        background-color: #fff;
        padding: 0 20px;
        border-bottom-left-radius: 8px;
        border-top-left-radius: 8px;
    }
    span{
        display: flex;
        box-sizing: border-box;
        align-items: center;
        justify-content: center;
        height: 80px;
        padding: 0 20px;
        background-color: #e3af2f;
        color: #fff;
        border-bottom-right-radius: 8px;
        border-top-right-radius: 8px;
    }
}
.tips{
    font-size: 24px;
    color: #999;
    padding: 0 20px;
}
.qrBox{
    display: flex;
    padding: 100px 0 0 0;
    justify-content: center;
    img{
        display: block;
        width: 500px;
    }
}
</style>